package com.hzlj.position.locate.converter;

import com.fz.common.base.converter.ModelDTOConverter;
import com.hzlj.common.message.common.dto.message.MessageNoticeResultDTO;
import com.hzlj.position.locate.common.dto.reportInspection.ReportInspectionNoticeDTO;
import com.hzlj.position.locate.common.enums.ReportStatus;
import com.hzlj.position.locate.common.model.ReportInspection;
import com.hzlj.position.locate.common.model.ReportInspectionArtificial;

import java.util.Date;

/**
 * 通信联络核查-核查(ReportInspection)DTO转换类
 *
 * @author lifh
 * @date 2023-07-21 14:20:19
 */
public class ReportInspectionConverter {

    public static ReportInspectionArtificial toArtificial(ReportInspection inspection) {
        ReportInspectionArtificial artificial = ModelDTOConverter.from(inspection, ReportInspectionArtificial.class);
        artificial.setId(inspection.getJzId());
        artificial.setInspectionId(inspection.getId());
        return artificial;
    }


    public static ReportInspection toSuccess(ReportInspectionNoticeDTO success, Date now) {
        ReportInspection update = to(success, now);
        update.setActualSpotCheckTime(now);
        update.setNotice(true);
        return update;
    }

    public static ReportInspection toFail(ReportInspectionNoticeDTO fail, MessageNoticeResultDTO notice, Date now) {
        ReportInspection update = to(fail, now);
        update.setNotice(false);
        update.setNoticeFailMsg(notice.getStatusMsg());
        return update;
    }

    private static ReportInspection to(ReportInspectionNoticeDTO t, Date now) {
        ReportInspection update = new ReportInspection();
        update.setId(t.getId());
        update.setJzId(t.getJzId());
        update.setReportType(t.getReportType());
        update.setBelongDay(t.getBelongDay());
        //防止状态冲突
        if (ReportStatus._WAIT.getStatus().equals(t.getReportStatus())) {
            update.setReportStatus(ReportStatus._NEVER.getStatus());
        }
        update.setUpdateTime(now);
        return update;
    }
}
